<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>发表文章</title>
<%@include file="/WEB-INF/jsps/header.jsp"%>
<link rel="stylesheet"
	href="${base }/res/kindeditor/themes/default/default.css" />
<script charset="utf-8" src="${base }/res/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="${base }/res/kindeditor/lang/zh_CN.js"></script>

<script type="text/javascript">
	var editor;
	$("document").ready(function() {
		editor = KindEditor.create('textarea[name="content"]', {
			cssPath : '${base }/res/kindeditor/plugins/code/prettify.css',
			uploadJson : '${admin_base }/resource/upload.at?id=%2Fr%2Fupload&flag=1',
			fileManagerJson : '${admin_base }/channelAttr/imageSelect.at',
			allowFileManager : true,
			urlType:"domain",
			afterBlur : function() {
				this.sync();
			}
		});

	});
	
	function getDesc(){
		if($("#description").val()==""){
			var htmlText = editor.text();
			$("#description").val(htmlText.substring(0,300)+(htmlText.length>300?"…………":""));
		}
	}
	
	
	function save(){
		
		getDesc();
		var form  = $("#form1");
		var valid = form.form("validate");
		if(valid){
			goAjax({
				url:form.attr("action"),
				data:$.serializeObject(form),
				callback:function(json){
					$.messager.alert('提示','保存成功','info',function(){
						parent.closeCurrentTab();
					});
				}
			});
		}
	}
	
</script>

</head>
<body>
	<form action="${admin_base}/content/save.at" id="form1">
		<input type="hidden" name="channelId" value="${channel.channelId }"/>
		<input type="hidden" name="contentId" value="${content.contentId }"/>
		<div style="width: 98%">
			<h2>栏目：${channel.channelName }</h2>
			<hr>
			<table style="border: 1px; width: 100%; padding: 20px;"
				cellSpacing="10">
				<tr>
					<th width="150px" align="center">标题</th>
					<td><input type="text" name="title"
						style="width: 800px; font: 16px arial; padding: 9px 7px;"
						placeholder="请输入标题" data-options="required:true" class="easyui-validatebox textbox" value="${content.title }"/></td>
				</tr>
				
				<tr>
					<th width="150px" align="center">摘要</th>
					<td>
						<textarea rows="20" cols="50" style="width: 810px;height: 80px" id="description" name="description">${content.description }</textarea>
					</td>
				</tr>

                <tr>
					<th width="150px" align="center">标题图片</th>
					<td>
                        <input type="text" id="titleImg" name="titleImg" value="${content.titleImg }" style="width: 750px; font: 16px arial; padding: 9px 7px;">
                        <button type="button" onclick="selectTpl('tplPath')" class="easyui-linkbutton">选择</button>
					</td>
				</tr>

				<tr>
					<th width="150px" align="center">内容</th>
					<td><textarea name="content"
							style="width: 850px; height: 400px; visibility: hidden;">${txt.txt }</textarea>
					</td>
				</tr>

				<tr>
					<td colspan="2">
					<a href="javascript:void(0)" data-options="iconCls:'icon-remove'" class="easyui-linkbutton"  style="margin: 10px 20px 0 350px;width: 120px;height: 30px" onclick="getDesc()">提取摘要</a>
					<a href="javascript:void(0)" data-options="iconCls:'icon-save'" class="easyui-linkbutton"  style="margin: 10px 0 0 10px;width: 80px;height: 30px" onclick="save()">保         存</a>
				 </td>
				</tr>
			</table>
		</div>
	</form>
    <div id="selectTpl2"></div>

<script type="text/javascript">
    function selectTpl(srcId){
        $("#selectTpl2").html("<ul id=\"t3\" class=\"easyui-tree\" url=\"fileList.at?type=r\" style='height:300px'>");
        $("#t3").tree({
            url:"${admin_base}/resource/fileList.at?type=r",
            onLoadSuccess:function(){
                $("#selectTpl2").dialog({
                    title:"选择图片",
                    width:500,
                    height:400,
                    modal : true,
                    closable : true,
                    buttons:[
                        {
                            text:"选择",
                            handler:function(){
                                getSelectResult(srcId);
                            }
                        }
                    ]
                });
            }
        });
    }

    function getSelectResult(srcId){
        var node = $('#t3').tree("getSelected");
        if(node!=null){
            $("#titleImg").val(node.id);
        }
        $("#selectTpl2").dialog("close");
    }
</script>
</body>
</html>